
var o;
Page({

    data: {
        goods:false,
        eri: '0',
        cat_id:0,
        catid:0,
        catid1:0,
        form: {
            number: 1
          },
        goods_list:[],
        background: [
            'https://assets.renrentuibao.com/web%2Fuploads%2Fimage%2Fstore_1%2Ff8c198b50e5a5473fcaaef9097d9bc6254025f47.jpg',
            'https://assets.renrentuibao.com/web%2Fuploads%2Fimage%2Fstore_1%2F435c09a18ab13165f1db6dff1b50a549a5270e34.jpg'
        ],
        puin: [],
        cats:[],
        navRightItems: [
        ],
        tagList: [],
        curNav: 0,
        tagNav: 0,
        tagText: "全部",
        HiddenTag: true
    },
    onLoad: function (t) {
        o = this
        getApp().page.onLoad(this, t);
        o.puindex();
    },
    keywords:function(e){
        wx.navigateTo({
          url: '/purchase/keywords/keywords',
        })
    },
    sping:function(e){
        wx.reLaunch({
          url: '/purchase/sping/sping',
        })
    },
    order:function(e){
        wx.reLaunch({
          url: '/purchase/order/order',
        })
    },
    puindex:function(e){
        getApp().request({
            url: getApp().api.purchase.index,
            // data:{
            //     cat_id:0
            // },
            success: function (e) {
                if (e.code == 0) {
                    o.setData({
                        puin:e.data.cat_list,
                        cat_id:e.data.cat_list[0].id
                    })
                    o.goods_list(e.data.cat_list[0].id)
                }
            },
            complete: function () {
                getApp().core.hideLoading();
            }
        });
    },
    god:function(e){
        console.log(e)
        var cat_id = e.currentTarget.dataset.id
        o.setData({
            cat_id:cat_id,
            catid:0,
            catid1:0
        })
        o.goods_list(cat_id)
    },
    changeTag:function(e){
        console.log(e)
        var catid = e.currentTarget.dataset.id
        o.setData({
            catid:catid
        })
        o.goods_list(catid)
    },
    changeTag1:function(e){
        console.log(e)
        var catid = e.currentTarget.dataset.id
        o.setData({
            catid1:catid
        })
        o.goods_list(catid)
    },
    goods_list: function (cat_id) {
        var a = this;
        getApp().core.showLoading({
            title: "加载中"
        }), getApp().request({
            url: getApp().api.purchase.goods_list,
            data: {
                page: 1,
                cat_id: cat_id
            },
            success: function (t) {
                if (0 === t.code) {
                    var e = t.data.list;
                    a.setData({
                        goods_list: e,
                        cats:t.data.cats
                    })
                }
            },
            complete: function () {
                getApp().core.hideLoading();
            }
        });
    },
    goodsInfo: function (t) {
        console.log('tt',t)
        var e = t.currentTarget.dataset.id;
        getApp().core.navigateTo({
          url: "/purchase/goods_info/goods_info?id=" + e
        });
      },

    numberSub: function() {
        var t = this.data.form.number;
        if (t <= 1) return !0;
        t--, this.setData({
            form: {
                number: t
            }
        });
    },
    gm:function(e){
      
        var shopping = wx.getStorageSync('shopping'),item = e.currentTarget.dataset.item
        console.log(e,shopping)
        if(shopping == undefined || shopping == ''){
            var sh = []
            sh.push(item)
            console.log('sh',sh)
           wx.setStorageSync('shopping',sh)
      
        }else{
            shopping.push(item)
            wx.setStorageSync('shopping',shopping)
        }
        wx.showToast({
            title: '添加购物车成功',
            icon: 'success',
            duration: 2000
          })
          
          
        // o.setData({
        //     goods:true
        // })
    },
    modalCloseGoods:function(e){
        o.setData({
            goods:false
        })
    }
});